//DevNETCoder
//CopyRight By DevNET Group
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using STT.Entities;
using STT.DataAccess;
 
namespace STT.Business
{
    public class BTbHuyen_Quan
    {
        //-----------------------------------------------------------//
        public static bool KiemTraDuLieu_Sua(ETbHuyen_Quan Huyen_Quan)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"TenHuyen_Quan", Huyen_Quan.TenHuyen_Quan);
            pr[1] = new SqlParameter(@"MaHuyen_Quan", Huyen_Quan.MaHuyen_Quan);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbHuyen_Quan_KiemTraDuLieu_Sua", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        //-----------------------------------------------------------//
        public static bool KiemTraDuLieu(ETbHuyen_Quan Huyen_Quan)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"TenHuyen_Quan", Huyen_Quan.TenHuyen_Quan);
           
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbHuyen_Quan_KiemTraDuLieu", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        //-----------------------------------------------------------//
        public static DataTable SearchHuyen_Quan(ETbHuyen_Quan Huyen_Quan)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"TenHuyen_Quan", Huyen_Quan.TenHuyen_Quan);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbHuyen_Quan_Search", pr);
            return all;
        }
        //-------------------------------------------------------------------
        public static DataTable SelectAll1()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbHuyen_Quan_SelectAll1", null);
            return all;
        }
//-----------------------------------------------------------//
        public static DataTable SelectAll()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbHuyen_Quan_SelectAll", null);
            return all;
        }
//-----------------------------------------------------------//
        public static void Insert(ETbHuyen_Quan OTbHuyen_Quan)
        {
            SqlParameter[] pr = new SqlParameter[3];
            pr[1] = new SqlParameter(@"TenHuyen_Quan", OTbHuyen_Quan.TenHuyen_Quan);
            pr[2] = new SqlParameter(@"MaTinh_TP", OTbHuyen_Quan.MaTinh_TP);
            pr[3] = new SqlParameter(@"TrangThai", OTbHuyen_Quan.TrangThai);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbHuyen_Quan_Insert", pr);
        }
//-----------------------------------------------------------//
        public static void Update(ETbHuyen_Quan OTbHuyen_Quan)
        {
            SqlParameter[] pr = new SqlParameter[4];
            pr[0] = new SqlParameter(@"MaHuyen_Quan", OTbHuyen_Quan.MaHuyen_Quan);
            pr[1] = new SqlParameter(@"TenHuyen_Quan", OTbHuyen_Quan.TenHuyen_Quan);
            pr[2] = new SqlParameter(@"MaTinh_TP", OTbHuyen_Quan.MaTinh_TP);
            pr[3] = new SqlParameter(@"TrangThai", OTbHuyen_Quan.TrangThai);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbHuyen_Quan_Update", pr);
        }
//-----------------------------------------------------------//
        public static void Delete(int MaHuyen_Quan)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaHuyen_Quan",MaHuyen_Quan);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbHuyen_Quan_Delete", pr);
        }
//-----------------------------------------------------------//
        public static ETbHuyen_Quan SelectByID(int MaHuyen_Quan)
        {
            ETbHuyen_Quan OTbHuyen_Quan = new ETbHuyen_Quan();
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaHuyen_Quan",MaHuyen_Quan);
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure,"TbHuyen_Quan_SelectByID", pr);
            if (idr.Read())
              OTbHuyen_Quan = GetOneTbHuyen_Quan(idr);
            idr.Close();
            idr.Dispose();
            return OTbHuyen_Quan;
        }
//-----------------------------------------------------------//
        private static ETbHuyen_Quan GetOneTbHuyen_Quan(IDataReader idr)
       {
            ETbHuyen_Quan OTbHuyen_Quan = new ETbHuyen_Quan();
                if (idr["MaHuyen_Quan"] != DBNull.Value)
                    OTbHuyen_Quan.MaHuyen_Quan = (int)idr["MaHuyen_Quan"];
                if (idr["TenHuyen_Quan"] != DBNull.Value)
                    OTbHuyen_Quan.TenHuyen_Quan = (string)idr["TenHuyen_Quan"];
                if (idr["MaTinh_TP"] != DBNull.Value)
                    OTbHuyen_Quan.MaTinh_TP = (int)idr["MaTinh_TP"];
                if (idr["TrangThai"] != DBNull.Value)
                    OTbHuyen_Quan.TrangThai = (int)idr["TrangThai"];
            return OTbHuyen_Quan;
       }
//-----------------------------------------------------------//
        public static bool TestByID(int MaHuyen_Quan)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaHuyen_Quan",MaHuyen_Quan);
            pr[1] = new SqlParameter(@"TestID",SqlDbType.Bit);
            pr[1].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbHuyen_Quan_TestByID", pr);
            return Convert.ToBoolean(pr[1].Value);
        }
//-----------------------------------------------------------//
        public static List<ETbHuyen_Quan> ListAll()
        {
            List<ETbHuyen_Quan> list = new List<ETbHuyen_Quan>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbHuyen_Quan_SelectAll", null);
            while (idr.Read())
              list.Add(GetOneTbHuyen_Quan(idr));
            if (idr.IsClosed == false)
            {
               idr.Close();
               idr.Dispose();
            }
            return list;
        }
    }
 
}
